/**
 * @fileoverview Script to update the eslint:recommended configuration.
 * @author aladdin-add<weiran.zsd@outlook.com>
 */

"use strict";

//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------

const fs = require("node:fs");
const builtInRules = require("../lib/rules");

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const recommendedRule = {};

for (const [ruleId, rule] of builtInRules) {
	if (!rule.meta.deprecated) {
		if (rule.meta.docs.recommended === true) {
			recommendedRule[ruleId] = "error";
		}
	}
}

const recommendedRulesText = JSON.stringify(
	recommendedRule,
	null,
	4,
).replaceAll("\n", "\n    ");

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------

const code = `/*
 * WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
 * script. Do not edit manually.
 */
"use strict";

module.exports = Object.freeze({
    name: "@eslint/js/recommended",
    rules: Object.freeze(${recommendedRulesText}),
});
`;

fs.writeFileSync(
	"./packages/js/src/configs/eslint-recommended.js",
	code,
	"utf8",
);
